package com.talent.jiwen_teacher.helper;

import android.annotation.SuppressLint;
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Build;

import com.talent.jiwen_teacher.R;
import com.talent.jiwen_teacher.base.App;

/**
 * Created by qyqx on 2018/8/27.
 */

public class SoundHelper {

    private SoundPool soundPool;
    private int idSure;
    private int idCanel;
    private int idOrder;

    private static SoundHelper helper;

    @SuppressLint("NewApi")
    @SuppressWarnings("deprecation")
    public SoundHelper() {
        Context context = App.getInstance();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            SoundPool.Builder spb = new SoundPool.Builder();
            spb.setMaxStreams(10);
            // spb.setAudioAttributes(null); // 转换音频格式
            soundPool = spb.build(); // 创建SoundPool对象

        } else {
            soundPool = new SoundPool(2, AudioManager.STREAM_SYSTEM, 5);
        }
//        idSure = soundPool.load(context, R.raw.h_sure_open, 1);
//        idCanel = soundPool.load(context, R.raw.h_cancel_back, 1);
        idOrder = soundPool.load(context, R.raw.xdd, 1);
    }

    public static SoundHelper get() {
        if (null == helper) {
            helper = new SoundHelper();
        }
        return helper;
    }

    public void palyOrder() {
        soundPool.play(idOrder, 1, 1, 10, 0, 1);

    }

//    public void palySure() {
//        if (BaseApplication.get().isOpenSoundBtn() && DefaultShared.isH()) {
//            soundPool.play(idSure, 1, 1, 0, 0, 1);
//        }
//
//    }
//
//    public void palyCancel() {
//        if (BaseApplication.get().isOpenSoundBtn() && DefaultShared.isH()) {
//            soundPool.play(idCanel, 1, 1, 0, 0, 1);
//        }
//    }

}
